package com.jh.user.service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import cn.jh.common.pay.jdpush.JiguangPush;
import cn.jpush.api.JPushClient;
import cn.jpush.api.common.ClientConfig;
import cn.jpush.api.common.resp.APIConnectionException;
import cn.jpush.api.common.resp.APIRequestException;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.Message;
import cn.jpush.api.push.model.Options;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.AndroidNotification;
import cn.jpush.api.push.model.notification.IosNotification;
import cn.jpush.api.push.model.notification.Notification;
import cn.jpush.api.push.model.notification.PlatformNotification;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.jfinal.kit.JsonKit;
import javafx.beans.binding.StringBinding;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.jh.common.utils.CommonConstants;
import cn.jh.common.utils.DateUtil;
import cn.jh.common.utils.TokenUtil;

import com.jh.user.business.BrandManageBusiness;
import com.jh.user.business.UserLoginRegisterBusiness;
import com.jh.user.business.UserRoleResourceBusiness;
import cn.jh.common.pay.jdpush.Jdpush;
import com.jh.user.pojo.Brand;
import com.jh.user.pojo.JdpushHistory;
import com.jh.user.pojo.User;
import com.jh.user.util.Util;


@Controller
public class UserJpushService {


    private static final Logger LOG = LoggerFactory.getLogger(UserJpushService.class);

    @Autowired
    private UserRoleResourceBusiness userRoleResourceBusiness;

    @Autowired
    private UserLoginRegisterBusiness userLoginRegisterBusiness;

    @Autowired
    Util util;
    @Autowired
    private BrandManageBusiness brandMangeBusiness;


    @Value("${version.ios.number}")
    private String IOSNum;

    @Value("${version.android.number}")
    private String AanroidNum;

    @Value("${version.android.url}")
    private String AanroidUrl;

    /***
     *
     * 推送测试
     * **/
    @RequestMapping(method = RequestMethod.POST, value = "/v1.0/user/jpush/test")
    public @ResponseBody
    Object setJpushtest(
            @RequestParam(value = "userId") long userId,
            //标题
            @RequestParam(value = "alert") String alert,
            //内容
            @RequestParam(value = "content") String content,
            //标识
            @RequestParam(value = "btype") String btype,
            //标识值
            @RequestParam(value = "btypeval") String btypeval
    ) {
        /*
         * 获取通道信息
         * *URL：/v1.0/user/brand/query/id
         * **/
        User user = userLoginRegisterBusiness.queryUserById(userId);

        Brand brand = brandMangeBusiness.findBrandById(user.getBrandId());

        String APPKEY = brand.getAppkey();
        String MASTERSECRET = brand.getMastersecret();
        JdpushHistory jdh = new JdpushHistory();
        jdh.setUserid(userId);
        jdh.setBrandId(brand.getId());
        jdh.setBtype(btype);
        jdh.setContent(content);
        jdh.setCreateTime(new Date());
        jdh.setTitle(alert);

        Map jdhmap = new HashMap();
        jdhmap.put(btype, btypeval);
        if (StringUtils.isNotBlank(APPKEY) && StringUtils.isNotBlank(MASTERSECRET)) {
            try {

                Jdpush.sendPushNotice(jdh.getUserid() + "", jdh.getTitle(), jdhmap, jdh.getContent(),APPKEY, MASTERSECRET);

                jdh = userRoleResourceBusiness.addJdpushHistory(jdh);


            } catch (Exception e) {
                LOG.info("=====异常信息:" + e);
            }

            userRoleResourceBusiness.delJdpushHistoryByUid(userId, 0);
        }

        Map map = new HashMap();
        map.put(CommonConstants.RESP_CODE, CommonConstants.SUCCESS);
        map.put(CommonConstants.RESULT, jdh);
        map.put(CommonConstants.RESP_MESSAGE, "成功");
        return map;

    }


    /***
     *
     * 平台推送
     * **/

    @RequestMapping(method = RequestMethod.POST, value = "/v1.0/user/jpush/test/brand")
    public @ResponseBody
    Object setJpushtestall(HttpServletRequest request,
                           @RequestParam(value = "brand_id") long brandId,
                           //标题
                           @RequestParam(value = "alert") String alert,
                           //内容
                           @RequestParam(value = "content") String content,
                           //截止时间
                           @RequestParam(value = "end_time", required = false) String endtime
    ) {
        /**
         * 获取通道信息
         * *URL：/v1.0/user/brand/query/id
         * **/

        Brand brand = brandMangeBusiness.findBrandById(brandId);

        String APPKEY = brand.getAppkey();
        String MASTERSECRET = brand.getMastersecret();

        JdpushHistory jdh = new JdpushHistory();
        jdh.setUserid(0);
        jdh.setBrandId(brandId);
        jdh.setBtype("marquee");
        jdh.setContent(content);
        jdh.setCreateTime(new Date());
        jdh.setEndTime(DateUtil.getYYMMHHMMSSDateFromStr(endtime));
        jdh.setTitle(alert);
        Map jdhmap = new HashMap();
        jdhmap.put("marquee", brand.getName());
        if (APPKEY != null && !APPKEY.equals("") && MASTERSECRET != null && !MASTERSECRET.equals("")) {
            Jdpush.sendPushNoticeAll(jdh.getTitle(), jdhmap, jdh.getContent(),APPKEY, MASTERSECRET);
            userRoleResourceBusiness.addJdpushHistory(jdh);
            LOG.info("UserJpushService_finduserroleresource", jdh.toString());
        }
        Map map = new HashMap();
        map.put(CommonConstants.RESP_CODE, CommonConstants.SUCCESS);
        map.put(CommonConstants.RESULT, jdh);
        map.put(CommonConstants.RESP_MESSAGE, "成功");
        return map;

    }

    /*
     *
     * 全平台推送
     * **/
    @RequestMapping(method = RequestMethod.POST, value = "/v1.0/user/jpush/tset/brands")
    public @ResponseBody
    Object setJpushtestalls(HttpServletRequest request,
                            //标题
                            @RequestParam(value = "alert") String alert,
                            //内容
                            @RequestParam(value = "content") String content,
                            //截止时间
                            @RequestParam(value = "end_time", required = false) String endtime) {

        JdpushHistory jdh = new JdpushHistory();
        List<Brand> resultList = brandMangeBusiness.findAllBrand();
        for (Brand list : resultList) {
            String APPKEY = list.getAppkey();
            String MASTERSECRET = list.getMastersecret();
            jdh.setUserid(0);
            jdh.setBrandId(list.getId());
            jdh.setBtype("marquee");
            jdh.setContent(content);
            jdh.setCreateTime(new Date());
            jdh.setEndTime(DateUtil.getYYMMHHMMSSDateFromStr(endtime));
            jdh.setTitle(alert);
            Map jdhmap = new HashMap();
            jdhmap.put("marquee", list.getName());

            if (APPKEY != null && !APPKEY.equals("") && MASTERSECRET != null && !MASTERSECRET.equals("")) {
                Jdpush.sendPushNoticeAll( jdh.getTitle(), jdhmap, jdh.getContent(),APPKEY, MASTERSECRET);
                userRoleResourceBusiness.addJdpushHistory(jdh);
                LOG.info("UserJpushService_finduserroleresource", jdh.toString());
            }
        }

        Map map = new HashMap();
        map.put(CommonConstants.RESP_CODE, CommonConstants.SUCCESS);
        map.put(CommonConstants.RESULT, jdh);
        map.put(CommonConstants.RESP_MESSAGE, "成功");
        return map;

    }

    /***
     *
     * 平台Android推送
     * **/

    @RequestMapping(method = RequestMethod.POST, value = "/v1.0/user/jpush/android/brand")
    public @ResponseBody
    Object setJpushtestall(HttpServletRequest request,
                           @RequestParam(value = "brand_id") long brandId,
                           //标题
                           @RequestParam(value = "alert") String alert,
                           //内容
                           @RequestParam(value = "content") String content,
                           //标识
                           @RequestParam(value = "btype") String btype,
                           //标识值
                           @RequestParam(value = "btypeval") String btypeval
    ) {
        /**
         * 获取通道信息
         * *URL：/v1.0/user/brand/query/id
         * **/
        Brand brand = brandMangeBusiness.findBrandById(brandId);
        String APPKEY = brand.getAppkey();
        String MASTERSECRET = brand.getMastersecret();
        JdpushHistory jdh = new JdpushHistory();
        jdh.setUserid(0);
        jdh.setBrandId(brandId);
        jdh.setBtype(btype);
        jdh.setContent(content);
        jdh.setCreateTime(new Date());
        jdh.setTitle(alert);
        Map jdhmap = new HashMap();
        jdhmap.put(btype, btypeval);
        if (APPKEY != null && !APPKEY.equals("") && MASTERSECRET != null && !MASTERSECRET.equals("")) {
            Jdpush.sendPushNoticeAndroid(jdh.getTitle(), jdhmap, jdh.getContent(),APPKEY,MASTERSECRET);
            userRoleResourceBusiness.delJdpushHistoryByuserId(0l, brandId, btype);
            userRoleResourceBusiness.addJdpushHistory(jdh);
            LOG.info("UserJpushService_finduserroleresource", jdh.toString());
        }
        Map map = new HashMap();
        map.put(CommonConstants.RESP_CODE, CommonConstants.SUCCESS);
        map.put(CommonConstants.RESULT, jdh);
        map.put(CommonConstants.RESP_MESSAGE, "成功");
        return map;

    }

    /***
     * sendPushNoticeAll
     * **/
    @RequestMapping(method = RequestMethod.POST, value = "/v1.0/user/jpush/history/add")
    public @ResponseBody
    Object addJdpushHistory(HttpServletRequest request,

                            @RequestParam(value = "userid") long userid,
                            @RequestParam(value = "btype") String btype,
                            @RequestParam(value = "content") String content,
                            @RequestParam(value = "title") String title

    ) {

        JdpushHistory jdh = new JdpushHistory();
        jdh.setUserid(userid);
        jdh.setBtype(btype);
        jdh.setContent(content);
        jdh.setCreateTime(new Date());
        jdh.setTitle(title);
        Map map = new HashMap();

        map.put(CommonConstants.RESP_CODE, CommonConstants.SUCCESS);
        map.put(CommonConstants.RESP_MESSAGE, "成功");
        map.put(CommonConstants.RESULT, userRoleResourceBusiness.addJdpushHistory(jdh));
        return map;
    }


    //查询推送记录
    @RequestMapping(method = RequestMethod.GET, value = "/v1.0/user/jpush/history/{token}")
    public @ResponseBody
    Object findJdpushHistory(HttpServletRequest request,
                             @PathVariable("token") String token,
                             @RequestParam(value = "user_id", defaultValue = "0", required = false) long user_Id,
                             @RequestParam(value = "page", defaultValue = "0", required = false) int page,
                             @RequestParam(value = "size", defaultValue = "20", required = false) int size,
                             @RequestParam(value = "order", defaultValue = "DESC", required = false) Sort.Direction direction,
                             @RequestParam(value = "sort", defaultValue = "createTime", required = false) String sortProperty
    ) {
        Map map = new HashMap();
        long userId;
        try {
            userId = TokenUtil.getUserId(token);
        } catch (Exception e) {
            map.put(CommonConstants.RESP_CODE, CommonConstants.ERROR_TOKEN);
            map.put(CommonConstants.RESP_MESSAGE, "token无效");
            return map;
        }

        Pageable pageable = new PageRequest(page, size, new Sort(direction, sortProperty));
        map.put(CommonConstants.RESP_CODE, CommonConstants.SUCCESS);
        map.put(CommonConstants.RESP_MESSAGE, "成功");
        if (user_Id != 0) {
            map.put(CommonConstants.RESULT, userRoleResourceBusiness.findJdpushHistoryByuserId(user_Id, pageable));
        } else {
            map.put(CommonConstants.RESULT, userRoleResourceBusiness.findJdpushHistoryByuserId(userId, pageable));
        }

        return map;
    }


    //查询推送记录
    @RequestMapping(method = RequestMethod.GET, value = "/v1.0/user/jpush/history/brand/{token}")
    public @ResponseBody
    Object findJdpushHistoryByBrand(HttpServletRequest request,
                                    @PathVariable("token") String token,
                                    @RequestParam(value = "brand_id", defaultValue = "-1", required = false) long brandId,
                                    @RequestParam(value = "page", defaultValue = "0", required = false) int page,
                                    @RequestParam(value = "size", defaultValue = "20", required = false) int size,
                                    @RequestParam(value = "order", defaultValue = "DESC", required = false) Sort.Direction direction,
                                    @RequestParam(value = "sort", defaultValue = "createTime", required = false) String sortProperty
    ) {
        Map<String, Object> map = new HashMap<String, Object>();
        long userId;
        try {
            userId = TokenUtil.getUserId(token);
        } catch (Exception e) {
            map.put(CommonConstants.RESP_CODE, CommonConstants.ERROR_TOKEN);
            map.put(CommonConstants.RESP_MESSAGE, "token无效");
            return map;
        }
        User user = userLoginRegisterBusiness.queryUserById(userId);
        if (brandId != -1) {
            userRoleResourceBusiness.delJdpushHistoryByUid(0, brandId);
        } else {
            userRoleResourceBusiness.delJdpushHistoryByUid(0, user.getBrandId());
        }
        if (page < 0) {
            page = 0;
        }
        Pageable pageable = new PageRequest(page, size, new Sort(direction, sortProperty));
        map.put(CommonConstants.RESP_CODE, CommonConstants.SUCCESS);
        map.put(CommonConstants.RESP_MESSAGE, "成功");
        if (brandId != -1) {
            map.put(CommonConstants.RESULT, userRoleResourceBusiness.findJdpushHistoryByBrandId(brandId, pageable));
        } else {
            map.put(CommonConstants.RESULT, userRoleResourceBusiness.findJdpushHistoryByBrandId(user.getBrandId(), pageable));
        }

        return map;
    }


    //通过id删除推送
    @RequestMapping(method = RequestMethod.POST, value = "/v1.0/user/jpush/history/delete")
    public @ResponseBody
    Object deleteJdpushHistoryById(HttpServletRequest request,
                                   @RequestParam(value = "id") long id) {
        Map map = new HashMap();
        try {
            userRoleResourceBusiness.delJdpushHistoryById(id);
            map.put(CommonConstants.RESP_CODE, CommonConstants.SUCCESS);
            map.put(CommonConstants.RESP_MESSAGE, "删除成功");
        } catch (Exception e) {
            map.put(CommonConstants.RESP_CODE, CommonConstants.FALIED);
            map.put(CommonConstants.RESP_MESSAGE, "删除失败");
            LOG.error(e.getMessage());
        }
        return map;
    }

    /**
       * 推送给设备标识参数的用户
       * @return 0推送失败，1推送成功
       */
    @RequestMapping(method = RequestMethod.POST, value = "/v1.0/user/jpush/sendPayAsk")
    public Object synPayAsk(@RequestParam(value = "userId") String userId,
                            //支付类型
                            @RequestParam(value = "type") String type,
                            //支付金额
                            @RequestParam(value = "money") String money) {


        String result = "0";
        User user = userLoginRegisterBusiness.queryUserById(Long.parseLong(userId));
        try {
            String extrasparam = "";
            Brand brand = brandMangeBusiness.findBrandById(user.getBrandId());
            JPushClient jPushClient = new JPushClient(brand.getMastersecret(),brand.getAppkey());
            String source = user.getSource();
            StringBuilder builder = new StringBuilder();

            String msg_title = "开店管家商户"+ user.getFullname() + ",手机号：" + user.getPhone() + "收款消息";//消息内容标题
            builder.append("开店管家");//消息内容
            PushPayload pushPayload;
            if(type.equals("alipay")){
                builder.append("支付宝");
            }else if(type.equals("weixin")){
                builder.append("微信");
            }
            String msg_content = builder.append("收款" + money + "元").toString();
            String notification_title = msg_content;
            if (source.toUpperCase().equals("IOS")) {
                pushPayload = buildPushObject_iod_registrationId_alertWithTitle(user.getDeviceId(), notification_title,
                        msg_title, msg_content, extrasparam);
            } else {

                pushPayload = buildPushObject_android_registrationId_alertWithTitle(user.getDeviceId(), notification_title,
                        msg_title, msg_content, extrasparam);
            }

            LOG.info("推送给设备标识参数的用户" + pushPayload);
            PushResult pushResult = jPushClient.sendPush(pushPayload);
            LOG.info("推送结果" + pushResult);

            JdpushHistory jdh = new JdpushHistory();
            jdh.setUserid(Long.parseLong(userId));
            jdh.setBrandId(brand.getId());
            jdh.setCreateTime(new Date());
            jdh.setTitle("开店管家");

            jdh.setDeviceId(user.getDeviceId());//设备编号
            jdh.setSource(user.getSource());//来源
            Map jdhmap = new HashMap();
            jdhmap.put(type, money);
            if(type.equals("alipay")){
                jdh.setBtype("支付宝");

            }else if(type.equals("weixin")){
                jdh.setBtype("微信");

            }
            jdh.setContent(jdh.getBtype()+"到账"+money+"元");
            if (pushResult.getResponseCode() == 200) {
                result = "1";
                userRoleResourceBusiness.addJdpushHistory(jdh);
            }
            userRoleResourceBusiness.delJdpushHistoryByUid(Long.valueOf(userId), 407);
        } catch (APIConnectionException e) {
            LOG.info("APIConnectionException 语音包发送失败user {} error {}",user.getId(),e.getMessage());
            e.printStackTrace();
        } catch (APIRequestException e) {
            LOG.info("APIRequestException 语音包发送失败user {} error {}",user.getId(),e.getMessage());
            e.printStackTrace();
        }
        return result;
    }

    private static PushPayload buildPushObject_android_registrationId_alertWithTitle(String registrationId,
                                                                                 String notification_title,
                                                                                 String msg_title,
                                                                                 String msg_content,
                                                                                 String extrasparam) {
        return PushPayload.newBuilder()
                //指定要推送的平台，all代表当前应用配置了的所有平台，也可以传android等具体平台
                .setPlatform(Platform.android())
                //指定推送的接收对象，all代表所有人，也可以指定已经设置成功的tag或alias或该应应用客户端调用接口获取到的registration id
                .setAudience(Audience.registrationId(registrationId))
                //jpush的通知，android的由jpush直接下发，iOS的由apns服务器下发，Winphone的由mpns下发
                .setNotification(Notification.newBuilder()
                        //指定当前推送的android通知
                        .addPlatformNotification(AndroidNotification.newBuilder()
                                .setAlert(notification_title)
                                .setTitle(notification_title)
                                //此字段为透传字段，不会显示在通知栏。用户可以通过此字段来做一些定制需求，如特定的key传要指定跳转的页面
                                .addExtra("androidNotification extras key",extrasparam)
                                .build())
                        .build())
                //Platform指定了哪些平台就会像指定平台中符合推送条件的设备进行推送。 jpush的自定义消息，
                // sdk默认不做任何处理，不会有通知提示。建议看文档http://docs.jpush.io/guideline/faq/的
                // [通知与自定义消息有什么区别？]了解通知和自定义消息的区别
                .setMessage(Message.newBuilder()
                        .setMsgContent(msg_content)
                        .setTitle(msg_title)
                        .addExtra("message extras key",extrasparam)
                        .build())
                .setOptions(Options.newBuilder()
                        //此字段的值是用来指定本推送要推送的apns环境，false表示开发，true表示生产；对android和自定义消息无意义
                        .setApnsProduction(false)
                        //此字段是给开发者自己给推送编号，方便推送者分辨推送记录
                        .setSendno(1)
                        //此字段的值是用来指定本推送的离线保存时长，如果不传此字段则默认保存一天，最多指定保留十天；
                        .setTimeToLive(86400)
                        .build())
                .build();
    }

    private static PushPayload buildPushObject_iod_registrationId_alertWithTitle(String registrationId,
                                                                                 String notification_title,
                                                                                 String msg_title,
                                                                                 String msg_content,
                                                                                 String extrasparam) {
        return PushPayload.newBuilder()
                //指定要推送的平台，all代表当前应用配置了的所有平台，也可以传android等具体平台
                .setPlatform(Platform.ios())
                //指定推送的接收对象，all代表所有人，也可以指定已经设置成功的tag或alias或该应应用客户端调用接口获取到的registration id
                .setAudience(Audience.registrationId(registrationId))
                //jpush的通知，android的由jpush直接下发，iOS的由apns服务器下发，Winphone的由mpns下发
                .setNotification(Notification.newBuilder()
                        //指定当前推送的iOS通知
                        .addPlatformNotification(IosNotification.newBuilder()
                                //传一个IosAlert对象，指定apns title、title、subtitle等
                                .setAlert(notification_title)
                                //直接传alert
                                //此项是指定此推送的badge自动加1
                                .incrBadge(1)
                                //指定后台推送
                                .setContentAvailable(true)
                                //此字段的值default表示系统默认声音；传sound.caf表示此推送以项目里面打包的sound.caf声音来提醒，
                                // 如果系统没有此音频则以系统默认声音提醒；此字段如果传空字符串，iOS9及以上的系统是无声音提醒，以下的系统是默认声音
                                .setSound("sound.caf")
                                //此字段为透传字段，不会显示在通知栏。用户可以通过此字段来做一些定制需求，如特定的key传要指定跳转的页面
                                .addExtra("iosNotification extras key",extrasparam)
                                .build())
                        .build())
                //Platform指定了哪些平台就会像指定平台中符合推送条件的设备进行推送。 jpush的自定义消息，
                // sdk默认不做任何处理，不会有通知提示。建议看文档http://docs.jpush.io/guideline/faq/的
                // [通知与自定义消息有什么区别？]了解通知和自定义消息的区别
                .setMessage(Message.newBuilder()
                        .setMsgContent(msg_content)
                        .setTitle(msg_title)
                        .addExtra("content-available",1)
                        .build())
                .setOptions(Options.newBuilder()
                        //此字段的值是用来指定本推送要推送的apns环境，false表示开发，true表示生产；对android和自定义消息无意义
                        .setApnsProduction(false)
                        //此字段是给开发者自己给推送编号，方便推送者分辨推送记录
                        .setSendno(1)
                        //此字段的值是用来指定本推送的离线保存时长，如果不传此字段则默认保存一天，最多指定保留十天；
                        .setTimeToLive(86400)
                        .build())
                .build();
    }

     /**
      * 推送到账提醒
      * @param userId
      * @param type
      * @param money
      * @return
      */
    //@RequestMapping(method = RequestMethod.POST, value = "/v1.0/user/jpush/sendPayAsk")
    public @ResponseBody Object sendPayAsk(
            @RequestParam(value = "userId") String userId,
            //支付类型
            @RequestParam(value = "type") String type,
            //支付金额
            @RequestParam(value = "money") String money
    ) {
        /*
         * 获取通道信息
         * *URL：/v1.0/user/brand/query/id
         * **/
        User user = userLoginRegisterBusiness.queryUserById(Long.parseLong(userId));

        Brand brand = brandMangeBusiness.findBrandById(user.getBrandId());

        String APPKEY = brand.getAppkey();
        String MASTERSECRET = brand.getMastersecret();

        JdpushHistory jdh = new JdpushHistory();
        jdh.setUserid(Long.parseLong(userId));
        jdh.setBrandId(brand.getId());
        jdh.setCreateTime(new Date());
        jdh.setTitle("开店管家");

        jdh.setDeviceId(user.getDeviceId());//设备编号
        jdh.setSource(user.getSource());//来源
        Map jdhmap = new HashMap();
        jdhmap.put(type, money);
        if (StringUtils.isNotBlank(APPKEY) && StringUtils.isNotBlank(MASTERSECRET)) {
            try {
                if(type.equals("alipay")){
                    jdh.setBtype("支付宝");

                }else if(type.equals("weixin")){
                    jdh.setBtype("微信");

                }
                jdh.setContent(jdh.getBtype()+"到账"+money+"元");
                Jdpush.sendPushNotice(jdh.getSource(),jdh.getDeviceId(),jdh.getUserid() + "", jdh.getTitle(), jdhmap, jdh.getContent(),APPKEY,MASTERSECRET);
//                JiguangPush.push("开店管家",msg,APPKEY,MASTERSECRET);

                jdh = userRoleResourceBusiness.addJdpushHistory(jdh);


            } catch (Exception e) {
                LOG.info("=====异常信息:" + e);
            }

            userRoleResourceBusiness.delJdpushHistoryByUid(Long.parseLong(userId), 0);
        }

        Map map = new HashMap();
        map.put(CommonConstants.RESP_CODE, CommonConstants.SUCCESS);
        map.put(CommonConstants.RESULT, jdh);
        map.put(CommonConstants.RESP_MESSAGE, "成功");
        return map;

    }

}
